package com.lt.schoolchat.model.enums;

import io.swagger.annotations.ApiModel;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @description:
 * @author: ~Teng~
 * @date: 2023/3/16 10:36
 */
@ApiModel("文件上传业务类型枚举")
@Getter
public enum FileUploadBizEnum {
    USER_AVATAR("用户头像", "user_avatar"),
    USER_VIDEO_COVER("用户视频封面", "user_video_cover"),
    USER_VIDEO("用户小视频", "user_video");

    private final String text;
    private final String value;

    FileUploadBizEnum(String text, String value) {
        this.text = text;
        this.value = value;
    }

    /**
     * 获取值列表
     */
    public static List<String> getValues() {
        return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList());
    }

    /**
     * 根据 value 获取枚举值
     */
    public static FileUploadBizEnum getEnumByValue(String value) {
        if (StringUtils.isBlank(value)) {
            return null;
        }
        for (FileUploadBizEnum fileUploadBizEnum : FileUploadBizEnum.values()) {
            if (fileUploadBizEnum.value.equals(value)) {
                return fileUploadBizEnum;
            }
        }
        return null;
    }
}
